package com.such.kitx.tax.impl;

import java.util.List;
import java.util.Map;
import org.apache.commons.collections4.multimap.ArrayListValuedHashMap;
import com.such.kit.validate.ValidateCommons;
import com.such.kitx.tax.TaxHelper;
import com.such.kitx.tax.TaxInterface;

/**
 * @author SUCH
 * <pre>
 * {@link TaxInterface} 的抽象实现类
 * 抽象类中定义了一些通用的变量、方法
 * </pre>
 * @see TaxInterface
 */
public abstract class AbstractTax implements TaxInterface {

	protected String taxVendor;
	protected String interfaceVersion;
	protected ArrayListValuedHashMap<String, String> templateMap = new ArrayListValuedHashMap<String, String>();

	protected AbstractTax(String taxVendor, String interfaceVersion) {
		this.taxVendor = taxVendor;
		this.interfaceVersion = interfaceVersion;
	}

	/**
	 * <pre>
	 * 添加接口方法与 xml 模板间的映射关系，既此方法需要使用那些 xml 模板
	 * </pre>
	 * @param methodName 方法名称
	 * @param templates 模板名称集
	 */
	protected void addTemplateMap(String methodName, String... templates) {
		if (ValidateCommons.isNotEmpty(templates)) {
			for (String template : templates) {
				this.templateMap.put(methodName, template);
			}
		}
	}

	public void printDataTemplate(Map<String, String> params) throws Exception {
		for (String template : this.templateMap.values()) {
			TaxHelper.printDataTemplate(this.taxVendor, this.interfaceVersion, template, params);
		}
	}

	public void printDataTemplate(String methodName, Map<String, String> params) throws Exception {
		List<String> templates = this.templateMap.get(methodName);
		if (ValidateCommons.isNotEmpty(templates)) {
			for (String template : templates) {
				TaxHelper.printDataTemplate(this.taxVendor, this.interfaceVersion, template, params);
			}
		}
	}

}
